Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more mssql datatypes #19105

Merged
merged 1 commit into from
Apr 19, 2024

Conversation

zgoldman-r7
Copy link
Contributor

This adds support for 7 new datatypes for MSSQL: float, real, money, smallmoney, datetime, smalldatetime, and numeric.

To test this, make sure you can connect to a remote mssql session, either via docker or VM.

use mssql_sql
run with credentials/connection info to the MSSQL instance, setting sql to a query that returns one of the new datatypes. ie:

query "select cast('1990-01-02' as datetime);"})}
query "select cast(null as datetime);"})}
query "select cast('1990-01-02' as smalldatetime);"})}
query "select cast('19900' as float);"})}
query "select cast(null as float);"})}
query "select cast('19900' as real);"})}
query "select cast(null as real);"})}
query "select cast('12.50' as money);"})}
query "select cast(null as money);"})}
query "select cast('12.50' as smallmoney);"})}
query "select cast(null as smallmoney);"})}
query "select cast('1999999900' as numeric(16, 6));"})}
query "select cast(null as numeric);"})}

checking null as well

Validate that output response looks okay

@zgoldman-r7 zgoldman-r7 changed the title add more datatypes add more mssql datatypes Apr 17, 2024
@@ -41,6 +41,57 @@ def test_console_query
end
end

def test_datatypes
it "should support datetime TDS datatype" do
Copy link
Contributor

@adfoster-r7 adfoster-r7 Apr 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of string matching the console we should test the Ruby result

[
  query: 'select cast(null as datetime);', expected: [[nil]],
  query: 'select cast('1990-01-02' as datetime);', expected: [['1990-01-02']],
  ...
].each do |test|
  it "should execute the query #{test[:query]} and return #{test[:expected]}" do
      ret = console.client.query(test[:query]) == test[:expected]
  end
end

Which would make it easier to add more tests in the future, as well as ensuring we can test the nil scenarios

@zgoldman-r7 zgoldman-r7 force-pushed the add-more-mssql-datatypes branch from b4e9bf2 to 1ff7d47 Compare April 18, 2024 17:55
@zgoldman-r7 zgoldman-r7 force-pushed the add-more-mssql-datatypes branch 2 times, most recently from 2362138 to 1050840 Compare April 18, 2024 20:28
{query: "select cast('1999999900' as numeric(16, 6));", expected: [[1999999900.0]]},
{query: "select cast(null as numeric(16, 6));", expected: [[nil]]},
].each do |test|
it "should execute the query #{test[:query]} and return #{test[:expected] || 'nil'}" do
Copy link
Contributor

@adfoster-r7 adfoster-r7 Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would mark false as nil

Suggested change
it "should execute the query #{test[:query]} and return #{test[:expected] || 'nil'}" do
it "should execute the query #{test[:query]} and return #{test[:expected].inspect}" do

@zgoldman-r7 zgoldman-r7 force-pushed the add-more-mssql-datatypes branch from 1050840 to 7659f52 Compare April 19, 2024 13:36
@zgoldman-r7 zgoldman-r7 force-pushed the add-more-mssql-datatypes branch from 7659f52 to b4dccdf Compare April 19, 2024 13:38
@adfoster-r7 adfoster-r7 merged commit 92592f9 into rapid7:master Apr 19, 2024
36 of 37 checks passed
@adfoster-r7 adfoster-r7 added the rn-enhancement release notes enhancement label Apr 19, 2024
@adfoster-r7
Copy link
Contributor

Release Notes

Updates MSSQL modules to support querying multiple new column types: float, real, money, smallmoney, datetime, smalldatetime, and numeric

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rn-enhancement release notes enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants